package com.example.zhongyingkaoshi.controller;


import com.example.zhongyingkaoshi.service.ExamStatsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

// 新建的统计控制器
@RestController
@RequestMapping("/api/stats")
public class ExamStatsController {

    @Autowired
    private ExamStatsService examStatsService;

    @PostMapping("/collect-and-send")
    public String triggerImmediateReport() {
        try {
            // 先执行数据收集
            examStatsService.performDailyStats();
            // 再发送即时报告
            examStatsService.sendImmediateReport();
            return "成绩报告已成功生成并发送";
        } catch (Exception e) {
            e.printStackTrace();
            return "报告生成失败: " + e.getMessage();
        }
    }

    @PostMapping("/collect-data")
    public String collectDailyData() {
        examStatsService.performDailyStats();
        return "当日考试数据已收集完成";
    }
}